home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Demos
/
A.D. Software
/
OOFILE
/
Buildable, limited OOFILE
/
samples
/
ooftst06.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-25
|
2KB
|
74 lines
// Copyright 1994 A.D. Software. All Rights Reserved
// OOFTEST6
// this sample modifies related data
// including demonstrating the caching of related records
// as would typically be used in a GUI environment
// Simple stream I/O is used to interact with the user.
#include "oofile.hpp"
#include "ooftst02.inc"
// included in ooftst2, 3, 4, 6, 9 & 15
int main()
{
cout << "OOFILE Validation Suite - Test 6\n"
<< "Simple test to demonstrate updating related fields" << endl
<< "using the database from ooftst02" << endl;
if (dbConnect::fileExists("ooftst06.db")) {
theDB.openConnection("ooftst06.db");
Patients.deleteAll();
}
else {
theDB.newConnection("ooftst06.db");
}
Patients.AddTestData();
dbView smithVisits(Patients.Visits);
smithVisits << Patients.Visits->VisitDate << Patients.Visits->Why;
Patients.search(Patients.LastName=="Smith");
cout << "Dumping Smith and his visits: " << endl
<< Patients << endl
<< smithVisits << endl;
cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
Patients.Visits->gotoRecord(0);
Patients.Visits->Why = "Computer-Induced Sanity";
cout << "changing the second reason to 'Funny Views' " << endl;
smithVisits.source()->gotoRecord(1); // test navigating via the view
smithVisits.field(1) = "Funny Views";
Patients.saveRecord(); // save both changes
cout << "Dumping Smith and changed visits: " << endl
<< Patients << endl
<< smithVisits << endl;
Patients.AddVisit("14/2/1995", "Anxiety Attacks");
// now change to another related record - our new one should be cached
smithVisits.source()->gotoRecord(1);
smithVisits.field(1) = "Changed Again";
// return to the new record (in the cache) and update it
smithVisits.source()->gotoRecord(2);
smithVisits.field(0) = "15/2/1994";
Patients.saveRecord();
cout << "Dumping Smith and visits with added visit: " << endl
<< Patients << endl
<< smithVisits << endl;
cout << "Now dumping the entire Visits file: " << endl << Visits;
cout << "done" << endl;
return EXIT_SUCCESS;
}